package com.tanhua.api.impl.mongo;

import com.tanhua.api.mongo.ReportApi;
import com.tanhua.domain.mongo.Dimensions;
import com.tanhua.domain.mongo.Report;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;

import java.util.List;

@Service
public class ReportApiImpl implements ReportApi {

    @Autowired
    private MongoTemplate mongoTemplate;

    @Override
    public Report findReportById(String reportId) {
        Query query = new Query(Criteria.where("reportId").is(reportId));
        Report report = mongoTemplate.findOne(query, Report.class);
        return report;
    }

    @Override
    public List<Dimensions> findDimendionsById(String reportId) {
        Query query = new Query(Criteria.where("reportId").is(reportId));
        List<Dimensions> dimensionsList = mongoTemplate.find(query, Dimensions.class);
        return dimensionsList;
    }
}
